package com.example.module_maintenance.adapter

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.module_maintenance.R
import com.example.module_maintenance.entity.VisitorEntity

class VisitorAdapter :
    BaseQuickAdapter<VisitorEntity, BaseViewHolder>(R.layout.item_visitor_management) {
    override fun convert(holder: BaseViewHolder, item: VisitorEntity) {
        holder.setText(R.id.item_visitor_management_reason, "来访事由:${item.purpose}")
        holder.setText(R.id.item_visitor_management_name, item.visitorName)
        holder.setText(R.id.item_visitor_management_time, item.appointmentTime)
        holder.setText(R.id.item_visitor_management_phone, item.phoneNumber)
        holder.setText(R.id.item_visitor_management_object, "访问对象：" + item.employeeId.toString())

        //根据状态设置不同背景和颜色
        //when表达式
        when (item.visitStatus) {
            "已通过" -> {
                holder.setText(R.id.item_visitor_management_status, "已通过")
                holder.setBackgroundResource(
                    R.id.item_visitor_management_status, R.drawable.shape_d1fae5_corner6
                )
                holder.getView<TextView>(R.id.item_visitor_management_status)
                    .setTextColor(Color.parseColor("#065f46"))
            }
            "待审核" -> {
                holder.setText(R.id.item_visitor_management_status, "待审核")
                holder.setBackgroundResource(
                    R.id.item_visitor_management_status, R.drawable.shape_d1fae5_corner7
                )
                holder.getView<TextView>(R.id.item_visitor_management_status)
                    .setTextColor(Color.parseColor("#92400E"))
            }
            "驳回" -> {
                holder.setText(R.id.item_visitor_management_status, "驳回")
                holder.setBackgroundResource(
                    R.id.item_visitor_management_status, R.drawable.shape_d1fae5_corner8
                )
                holder.getView<TextView>(R.id.item_visitor_management_status)
                    .setTextColor(Color.parseColor("#ef4444"))
            }
            "已完成" -> {
                holder.setText(R.id.item_visitor_management_status, "已完成")
                holder.setBackgroundResource(
                    R.id.item_visitor_management_status, R.drawable.shape_d1fae5_corner9
                )
                holder.getView<TextView>(R.id.item_visitor_management_status)
                    .setTextColor(Color.parseColor("#374151"))
            }
        }

        //判断申请车位
        if (item.requestParking){
            holder.setText(R.id.item_visitor_management_parking_info,"已申请访客车位:B区-3号")
            holder.getView<TextView>(R.id.item_visitor_management_parking_info)
                .setTextColor(Color.parseColor("#1e88e5"))
            holder.setBackgroundResource(
                R.id.item_visitor_management_car_icon,
                R.drawable.baseline_airport_shuttle_1e88e5_24
            )
        }else{
            holder.setText(R.id.item_visitor_management_parking_info,"未申请访客车位:")
            holder.getView<TextView>(R.id.item_visitor_management_parking_info)
                .setTextColor(Color.parseColor("#9ca3af"))
            holder.setBackgroundResource(
                R.id.item_visitor_management_car_icon,
                R.drawable.baseline_airport_shuttle_9ca3af_24
            )
        }
    }
}